package com.iemes.controller.warehouse;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.OvertimeanalyzeFormMap;
import com.iemes.mapper.warehouse.OvertimeanalyzeMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
import com.iemes.util.MyDateUtils;

@RequestMapping("/overtimeanalyze_form/")
@Controller
public class Overtimeanalyze_FormController extends BaseController {

	@Inject
	private OvertimeanalyzeMapper overtimeanalyzeMapper;

	// 查看库存超期异常原因分析单，显示按钮。
	@RequestMapping("overtimeanalyze_form")
	public String overtimeanalyze_form(Model model) {
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/warehouse/overtimeanalyze_form_list";
	}

	// 库存超期异常原因分析单分页
	@ResponseBody
	@RequestMapping("overtimeanalyze_form_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception {
		OvertimeanalyzeFormMap overtimeanalyzeFormMap = getFormMap(OvertimeanalyzeFormMap.class);
		overtimeanalyzeFormMap.put("formCategory", 1);
		overtimeanalyzeFormMap.put("outFinished", 1);
//		List<Map<String, Object>> over = overtimeanalyzeMapper.getAllGt7(overtimeanalyzeFormMap);
		//测试用，以后须换成上面的getAllGt7
		List<Map<String, Object>> over = overtimeanalyzeMapper.getAll(overtimeanalyzeFormMap);
		LuogicPaging(pageNow, pageSize, over);
		return pageView;
	}

	// 编辑库存超期异常原因分析单
	@RequestMapping("overtimeanalyze_form_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			//根据id获得库存超期异常原因分析单
			OvertimeanalyzeFormMap over=overtimeanalyzeMapper.getById(id);
			model.addAttribute("over",over);
		}
		return Common.BACKGROUND_PATH + "/warehouse/overtimeanalyze_form_edit";
	}

	// 修改库存超期异常原因分析单
	@ResponseBody
	@RequestMapping(value = "overtimeanalyze_form_editEntity")
	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module = "编辑库存超期异常原因分析单", methods = "库存超期异常原因分析单-修改库存超期异常原因分析单") // 凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity(HttpServletRequest request) throws NumberFormatException, Exception {
		OvertimeanalyzeFormMap overtimeanalyzeFormMap=getFormMap(OvertimeanalyzeFormMap.class);
		String[] reason=request.getParameterValues("overtimeanalyzeFormMap.overtimeReason");
		StringBuffer sbf=new StringBuffer();
		if(reason!=null){
			for(int i=0;i<reason.length;i++){
				sbf.append(reason[i]+"，");
			}
		}
		if(sbf!=null && sbf.length()>0){
			overtimeanalyzeFormMap.put("overtimeReason", sbf.substring(0,sbf.length()-1));
		}
		try {
			baseMapper.editEntity(overtimeanalyzeFormMap);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return "success";
	}	
}



